package com.itheima07;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        // 创建服务器 socket
        ServerSocket ss = new ServerSocket(10000);

        // 监听客户端链接，返回 socket 对象
        Socket s = ss.accept();

        // 获取输入流
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        // 写入文件
        BufferedWriter bw = new BufferedWriter(new FileWriter("/Users/oscar/Desktop/HQWork/学习资料/code/MyNet/s.txt"));

        String line;
        while ((line = br.readLine()) != null) {
            bw.write(line);
            bw.newLine();
            bw.flush();
        }

        // 释放资源
        bw.close();
        ss.close();
    }
}
